package com.shop.cereshop.commons.domain.user.faceCheck;

import com.shop.cereshop.commons.config.RsaProperties;
import com.shop.cereshop.commons.utils.RsaUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "人脸检测模型")
@Slf4j
public class FaceCheckModel {
    /**
     * 调用方式  ali  txun baidu
     */
    @ApiModelProperty(value = "调用方式")
    private String type;

    /**
     * 图片base64编码
     */
    @ApiModelProperty(value = "图片base64编码   base64与url二选一")
    private String imageBase64;

    /**
     * 图片url
     */
    @ApiModelProperty(value = "图片url base64与url二选一")
    private String imageUrl;

    /**
     * 图片类型 1:url 2:base64
     */
    @ApiModelProperty(value = "图片类型 1:url 2:base64", required = true)
    private String imageType;

    /**
     * 姓名
     */
    @ApiModelProperty(value = "姓名 姓名需要加密传输", required = true)
    private String name;

    /**
     * 身份证号码
     */
    @ApiModelProperty(value = "身份证号码需要加密传输", required = true)
    private String idCardNumber;

    /**
     * 是否活体检测（0:不检测，1:检测）,默认0
     */
    @ApiModelProperty(value = "是否活体检测（0:不检测，1:检测）,默认0")
    private Integer liveck;

    public FaceCheckModel decrypt() throws Exception {
        FaceCheckModel res = this;
        try {
            res.setName(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, this.name));
            res.setIdCardNumber(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, this.idCardNumber));
        } catch (Exception e) {
//            e.printStackTrace();
            log.error("解密失败");
        }
        return res;
    }


    // 重写toString方法
    public String toString() {
        return "FaceCheckModel{" +
                "type='" + type + '\'' +
                ", imageBase64='" + imageBase64 + '\'' +
                ", imageUrl='" + imageUrl + '\'' +
                ", imageType='" + imageType + '\'' +
                ", name='" + name + '\'' +
                ", idCardNumber='" + idCardNumber + '\'' +
                ", liveck=" + liveck +
                '}';
    }

}
